package 链表题.删除有序链表重复节点_留一个;

import 链表题.ListNode;

/**
 * 方法二: 递归解法(留一个)
 */
public class Test2 {
    public static ListNode deleteDuplicates(ListNode head) {
        if (head == null || head.next == null) {
            return head;
        }
        if (head.val == head.next.val) {
            return deleteDuplicates(head.next);
        } else {
            head.next = deleteDuplicates(head.next);
            return head;
        }
    }

    public static void main(String[] args) {
        ListNode o5 = new ListNode(4,null);
        ListNode o4 = new ListNode(4,o5);
        ListNode o3 = new ListNode(3,o4);
        ListNode o2 = new ListNode(1,o3);
        ListNode o1 = new ListNode(0,o2);
        ListNode o = new ListNode(0,o1);
        System.out.println(o);
        System.out.println(deleteDuplicates(o));
    }
}
